<script type="text/javascript"><!--//--><![CDATA[//><!--

var LOVDataPerangkat = function(ao_option){
    try{
        if(ao_option==undefined){ ao_option={}; }
        var lf_onSelect = (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
        
        // Create Popup
        var $popup  = openPopup({ title:'Daftar Barang' , width:700, height:370 });
        var ls_id   = $popup.attr('id');
        
        // Append Datagrid Container
        var ls_gridName = 'grid_'+ls_id;
        $popup  .html(  $('<div>')  .attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
                                    .html(  $('<div>').html($('<form>') .attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
                                                                        .html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
                                                            )
                                            )
                        )
                .append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
        
        $('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
        $('#btn_search'+ls_id).linkbutton({  
            plain:true  
        }); 
        
        // Build Datagrid
        var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
        $('#'+ls_gridName).datagrid({  
            url:gs_path+'/pro_setup_stock/getdata2/'+ls_param,
            queryParams: $('#fm_search_'+ls_id).serializeObject(),
            height:337,
            pagination:true,
            singleSelect:true,
            columns:[[
                { field : 'kode_barang', title : 'Kode Barang', width : 100, sortable:true },
                { field : 'nama_barang', title : 'Nama Barang', width : 300, sortable:true },
                //{ field : 'harga', title : 'Harga', width : 300, sortable:true },
                //{ field : 'jumlah', title : 'Jumlah', width : 300, sortable:true },
                //{ field : 'kemasan', title : 'Kemasan', width:200, sortable:true },
                //{ field : 'isi', title : 'Isi', width:200, sortable:true }
            ]],
            onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
        });
        
    } catch (err) { alert('Func. LOVSampleReference :\n' + err); }
};

 	$(document).ready(function() {
		// Setup Form
		$('#form_master').setupForm([
            { name: 'id_penambahan_dtl', type: 'text', size: 'medium', maxlength: 20, readonly:true},
			{ name: 'id_barangan', type: 'lov', size: 'short',
				onClearButton:function(){
					$(this).setval(''); 
					$('#nama_barang').setval(''); 
				},
				onActionButton:function(){ 
					LOVDataPerangkat({ onSelect:function(row){ 
						$('#id_barangan').setval(row.kode_barang); 
						$('#nama_barang').setval(row.nama_barang); 
					} }); 
				}
			},
            { name: 'nama_barang', type: 'text', size: 'medium', maxlength: 20, readonly:true },
			{ name: 'jumlah', type: 'text', size: 'medium', maxlength: 20, noempty:true },
			{ name: 'lokasi', type: 'text', size: 'long', maxlength: 200},
			{ name: 'keterangan', type: 'text', size: 'long', maxlength: 200}
		], <?php echo json_encode($data); ?>);
		
        <?php if($mode=="edit_detail"){ ?>
        $('#id_penambahan_dtl').readonly();
        <?php } ?>

        <?php if($mode=="create_detail"){ ?>
        $('#id_penambahan_dtl').setval('<?php echo $numb_id_detail; ?>');
        <?php } ?>
		
		var buttons = [{ label: 'Save', icon: 'save', onclick: function() { 
							$('#form_master').submitForm(	'/'+controller+'/ajax_post_detail/<?php echo $this->uri->segment(2); ?>/<?php echo $this->uri->segment(3); ?>' );
                            loadPage('/'+controller+'/edit/?id_penambahan=<?php echo $this->uri->segment(3); ?>'); }/*, onclick: function() { loadPage('/'+controller+'/Index');} */
						},
					   { label: 'Close', icon: 'cancel', onclick: function() { loadPage('/'+controller+'/edit/?id_penambahan=<?php echo $this->uri->segment(3); ?>'); } }];
		setAction(buttons);

		
    });




//--><!]]></script>

<div id="form_master_message" style="display:none;"></div>
    <table class="tb_form" style="display:none;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label" style="width:150px">ID penambahan Perangkat Detail</td>
        <td colspan="2"><input id="id_penambahan_dtl" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Nama Barang</td>
        <td colspan="2"><input id="id_barangan" /><input id="nama_barang" name="nama_barang" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Jumlah</td>
        <td colspan="2"><input id="jumlah" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Lokasi</td>
        <td colspan="2"><input id="lokasi" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Keterangan</td>
        <td colspan="2"><input id="keterangan" /></td>
    </tr>
    </table>